﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ExtAspNet;
using BLL;

namespace WebUI.LabManage
{
    public partial class ConsumableRecord : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridBind();

        }

        private void InitForm()
        {
            tb_name.Text = "";
            dp_down_date.SelectedDate = null;
            dp_up_date.SelectedDate = null;
        }

        private void GridBind()
        {
            Grid1.DataSource = ConsumableRecordManage.GetList();
            Grid1.DataBind();
        }
        protected void bnReset_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(600);
            InitForm();
            GridBind();
        }
        protected void bnSearch_Click(object sender, EventArgs e)
        {
            StringBuilder strWhere = new StringBuilder();
            if (tb_name.Text != "" || dp_up_date.SelectedDate != null || dp_down_date.SelectedDate != null)
            {
                System.Threading.Thread.Sleep(600);
                if (tb_name.Text != "")
                {
                    strWhere.AppendFormat("Consumable.name LIKE '%{0}%' ", tb_name.Text);
                }
                if (dp_up_date.SelectedDate != null)
                {
                    if (tb_name.Text != "")
                    {
                        strWhere.Append(" AND ");
                    }
                    strWhere.AppendFormat("ConsumableRecord.date >= '{0}' ", dp_up_date.SelectedDate);
                }
                if (dp_down_date.SelectedDate != null)
                {
                    if (tb_name.Text != "" || dp_up_date.SelectedDate != null)
                    {
                        strWhere.Append(" AND ");
                    }
                    strWhere.AppendFormat("ConsumableRecord.date <= '{0}'", dp_down_date.SelectedDate);
                }
                Grid1.DataSource = ConsumableRecordManage.GetList(strWhere.ToString());
                Grid1.DataBind();
            }
            else
            {
                Alert.Show("请输入搜索条件！");
            }

        }
        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
        }
    }
}